<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2023/10/16
 * Time: 11:36 AM
 */

namespace app\zyhsapi\model;

use app\common\lib\Aes;
use think\Log;
use XznsTools\cache\zyhs\CacheManageZyhs;

class ZyhsBanner extends BaseCacheZyhs
{
    protected $table = 'good_wechatadmin.zyhs_banner';
    protected $cacheModel = 'index.slide';

    /**
     * 获取指定版本轮播图
     * @return array|mixed
     * @throws \Exception
     */
    public function versionBanner()
    {
        $header = request()->header();
        $versionName = 'V' . $header['version'];
        $ids = CacheManageZyhs::getInstance()->setCacheConfig($this->cacheModel, $header['app-type'] . '-' . $versionName)->setSort('DESC')->ZsGetIocData('list', function () use ($header, $versionName)
        {
            $where = ['sv.type' => 1, 'v.type' => $header['app-type'], 'v.version_name' => $versionName, 's.status' => 1];
            try
            {
                $ids = $this->alias('s')
                    ->join('good_wechatadmin.zyhs_banner_version sv', 's.id=sv.sid')
                    ->join('good_wechatadmin.zyhs_app_version v', 'sv.vid=v.id')
                    ->where($where)
                    ->order('sort DESC')->column('s.id');

                return array_flip_key_value($ids);
            }
            catch (\Exception $e)
            {
//                Log::write('banner获取失败：' . $e->getMessage(), 'slide_error', true);
                return [];
            }
        });
        return $this->batchGetInfoByIds($ids);
    }


    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->where(['id' => ['in', $ids]])->column('*', 'id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }
}
